<template>
	<view class="index">
		<view class="inputArea">
			<image class="logo-img" src="/static/images/money.png"></image>
		</view>
		<view class="text-xl padding text-center">
			<text class="text-black text-bold">记数簿</text>
		</view>
		<view class="text-s padding text-center">
			<text class="text-gray">家常记账，知悭识俭</text>
		</view>
		<view class="inputArea">
			<button class="login-button bg-gradual-orange" @click="getUserInfo">翻开记数簿</button>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {

			}
		},
		methods: {
			goLogin() {
				this.getUserInfo();
			},
			getUserInfo() {
				uni.getUserProfile({
					desc: '用户授权',
					success: (userInfo) => {
						let data = userInfo.userInfo;
						uni.login({
							provider: 'weixin',
							success: (loginRes) => {
								if (loginRes.errMsg == 'login:ok') {
									uniCloud.callFunction({
										name: 'baseCommon',
										data: {
											action: 'loginByWeixin',
											params: {
												code: loginRes.code
											}
										},
										success: (res) => {
											uni.setStorageSync('uni_id_token', res
												.result.token)
											uni.setStorageSync(
												'uni_id_token_expired', res
												.result.tokenExpired);
											data = {...data,...res.result.userInfo};
											data._id = res.result.uid;
											uni.setStorageSync('userInfo', data);
											uni.showToast({
												title: '登陆成功',
												success: () => {
													uni.switchTab({
														url: '/pages/bookkeeping/bookkeeping'
													});
												},
												fail: (err) => {
													console.log(err,
														'err')
												}
											})

										}
									})
									// uni.hideLoading();
								}
							},
							fail: (fail) => {
								uni.hideLoading();
								console.log(JSON.stringify(fail));
							}
						});
					},
					fail: (err) => {
						console.log(err, 'err')
					}
				})

			}
		}
	}
</script>

<style scoped>
	.index {
		padding-top: 40rpx;
	}

	.text-center {
		text-align: center;
	}

	.text-gray {
		color: gray;
	}

	.inputArea {
		padding: 30rpx 10%;
		text-align: center;
	}

	.text-s {
		margin: 30rpx 0;
	}

	.inputClass {
		border: 2px solid #ccc;
		border-radius: 44rpx;
		outline: 0;
		width: 90%;
		padding: 16rpx 30rpx;
		background-color: #FFFFFF;
	}

	.logo-img {
		width: 150rpx;
		height: 150rpx;
		border-radius: 150rpx;
	}

	.login-button {
		/* background: #2fc25b; */
		color: #FFFFFF;
		border-radius: 54rpx;
		font-size: 36rpx;
		text-align: center;
		padding: 20rpx;
	}

	.bg-gradual-orange {
		background-image: linear-gradient(45deg, #ff9700, #ed1c24);
		color: #ffffff;
	}
</style>
